<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.1">
  <xsl:output encoding="utf-8" method="xml"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="/">
    <collection xmlns:marc="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
      <marc:record>
        <marc:leader>00000nam a22000002a 4500</marc:leader>
        <marc:controlfield tag="008">       20uu9999   |||||s|||||00| 0|eng d </marc:controlfield>
        <xsl:apply-templates select="Session/Formdata"/>
      </marc:record>
    </collection>
  </xsl:template>

  <xsl:template match="Session/Formdata">

<!-- Resource Type -->
    <xsl:choose>
      <xsl:when test="resource_type">
        <marc:datafield tag="655" ind1=" " ind2="7">
          <marc:subfield code="a">
            <xsl:apply-templates select="resource_type"/>
          </marc:subfield>
          <marc:subfield code="2">local</marc:subfield>
        </marc:datafield>
        <xsl:variable name="rtype" select="resource_type"/>

<!-- NEED TO ADD CALL TO RESOURCE SPECIFIC TEMPLATES -->
        <xsl:if test="$rtype = 'Other Resource'">
          <xsl:call-template name="other_resource"/>
        </xsl:if>
        <xsl:if test="$rtype = 'Working Paper'">
          <xsl:call-template name="working_paper"/>
        </xsl:if>
        <xsl:if test="$rtype = 'Journal Article'">
          <xsl:call-template name="journal_article"/>
        </xsl:if>
        <xsl:if test="$rtype = 'Thesis'">
          <xsl:call-template name="thesis"/>
        </xsl:if>
        <xsl:if test="$rtype = 'Report'">
          <xsl:call-template name="report"/>
        </xsl:if>
        <xsl:if test="$rtype = 'Conference Paper'">
          <xsl:call-template name="conference_paper"/>
        </xsl:if>
        <xsl:if test="$rtype = 'Conference Item'">
          <xsl:call-template name="conference_item"/>
        </xsl:if>
        <xsl:if test="$rtype = 'Book Chapter'">
          <xsl:call-template name="book_chapter"/>
        </xsl:if>
        <xsl:if test="$rtype = 'Book'">
          <xsl:call-template name="book"/>
        </xsl:if>
      </xsl:when>
    </xsl:choose>

<!-- Language -->
    <xsl:choose>
      <xsl:when test="language">
        <marc:datafield tag="546" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="language"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Generic Title -->
    <xsl:choose>
      <xsl:when test="title">
        <marc:datafield tag="245" ind1="1" ind2="0">
          <marc:subfield code="a">
            <xsl:apply-templates select="title"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Abstract -->
    <xsl:choose>
      <xsl:when test="description_abstract">
        <marc:datafield tag="520" ind1="3" ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="description_abstract"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Subjects -->
<!-- NEED TO SPLIT 'subject' by \r -->
    <xsl:choose>
      <xsl:when test="subject">
        <xsl:call-template name="splitString">
          <xsl:with-param name="string1" select="subject"/>
        </xsl:call-template>
      </xsl:when>
    </xsl:choose>

<!-- Keywords -->
    <xsl:apply-templates select="*[starts-with(local-name(),'keyword')]"/>

<!-- Creators -->
    <xsl:choose>
      <xsl:when test="creators">
        <xsl:call-template name="splitStringNewline">
          <xsl:with-param name="stringLine" select="creators"/>
        </xsl:call-template>
      </xsl:when>
    </xsl:choose>

<!-- Publisher Statement -->
    <xsl:choose>
      <xsl:when test="publisher_statement">
        <marc:datafield tag="540" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="publisher_statement"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Additional Information -->
    <xsl:choose>
      <xsl:when test="additional_info">
        <marc:datafield tag="500" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:choose>
              <xsl:when test="other_resource_info">
                <xsl:call-template name="splitStringInfo">
                  <xsl:with-param name="stringLineInfo" select="other_resource_info"/>
                </xsl:call-template>
<!--
                <xsl:apply-templates select="other_resource_info"/>
-->
              </xsl:when>
            </xsl:choose>
            <xsl:call-template name="splitStringInfo">
              <xsl:with-param name="stringLineInfo" select="additional_info"/>
            </xsl:call-template>
<!--
            <xsl:apply-templates select="additional_info"/>
-->
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>


<!-- ======================= PREVIOUS CREATORS MAPPING ============================= -->
<!-- Creators -->
<!--
    <xsl:choose>
        <xsl:when test="creator_last_name">
           <marc:datafield tag="100" ind1=" " ind2=" ">
             <marc:subfield code="a">
               <xsl:apply-templates select="creator_last_name"/>, <xsl:apply-templates select="creator_first_name"/>
             </marc:subfield>
            </marc:datafield>
        </xsl:when>
    </xsl:choose>
-->

<!-- Other Creators -->
<!--
    <xsl:apply-templates select="*[starts-with(local-name(),'creator_last_name_')]"/>
-->

<!-- University -->
    <xsl:choose>
      <xsl:when test="university">
        <marc:datafield tag="710" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="university"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>
<!-- ==============================END PREVIOUS CREATORS MAPPING =================== -->


<!-- Faculty -->
<!-- NEED TO SPLIT 'faculty' by \r -->
<!--
    <xsl:choose>
      <xsl:when test="faculty">
        <xsl:call-template name="splitFaculty">
           <xsl:with-param name="string1" select="faculty"/>
        </xsl:call-template>
      </xsl:when>
    </xsl:choose>
-->

<!-- School -->
<!-- NEED TO SPLIT 'school' by \r -->
<!-- 
    <xsl:choose>
      <xsl:when test="school">
        <xsl:call-template name="splitSchool">
           <xsl:with-param name="string1" select="school"/>
        </xsl:call-template>
      </xsl:when>
    </xsl:choose>
-->

<!-- Research Unit -->
<!-- NEED TO SPLIT 'research_unit' by \r -->
<!--
    <xsl:choose>
      <xsl:when test="research_unit">
        <xsl:call-template name="splitResearch">
           <xsl:with-param name="string1" select="research_unit"/>
        </xsl:call-template>
      </xsl:when>
    </xsl:choose> 
-->

<!-- Rights 
    <xsl:choose>
      <xsl:when test="rights">
        <marc:datafield tag="540" ind1=" " ind2="0">

               <marc:subfield code="a"><xsl:apply-templates select="rights"/></marc:subfield>

          <marc:subfield code="a">The content is available under Creative Commons Attribution-NonCommercial-NoDerivs Licence. http://unsworks.unsw.edu.au/copyright</marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>
-->
<marc:datafield tag="540" ind1=" " ind2="0">
	<marc:subfield code="a">http://unsworks.unsw.edu.au/copyright</marc:subfield>
</marc:datafield>

  </xsl:template>


<!--##########################-->
<!-- Other Resources Template -->
<!--##########################-->
  <xsl:template name="other_resource">
    <xsl:choose>
      <xsl:when test="year">
        <marc:datafield tag="260" ind1=" " ind2=" ">
          <marc:subfield code="c">
            <xsl:apply-templates select="year"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>
  </xsl:template>


<!--##########################-->
<!-- Working Paper Template -->
<!--##########################-->
  <xsl:template name="working_paper">

<!-- ISBN -->
    <xsl:choose>
      <xsl:when test="working_paper_isbn">
        <marc:datafield tag="020" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="working_paper_isbn"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- ISSN -->
    <xsl:choose>
      <xsl:when test="working_paper_issn">
        <marc:datafield tag="022" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="working_paper_issn"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Title -->
    <xsl:choose>
      <xsl:when test="working_paper_title">
        <marc:datafield tag="830" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="working_paper_title"/>
          </marc:subfield>
          <marc:subfield code="v">
            <xsl:apply-templates select="working_paper_number"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Date -->
    <xsl:choose>
      <xsl:when test="year">
        <marc:datafield tag="260" ind1=" " ind2=" ">
          <xsl:choose>
            <xsl:when test="working_paper_publisher">
              <marc:subfield code="b">
                <xsl:apply-templates select="working_paper_publisher"/>
              </marc:subfield>
            </xsl:when>
          </xsl:choose>
          <xsl:choose>
            <xsl:when test="working_paper_place_publication">
              <marc:subfield code="a">
                <xsl:apply-templates select="working_paper_place_publication"/>
              </marc:subfield>
            </xsl:when>
          </xsl:choose>
          <marc:subfield code="c">
            <xsl:apply-templates select="year"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Peer Reviewed -->
    <xsl:choose>
      <xsl:when test="working_paper_peer_reviewed">
        <marc:datafield tag="787" ind1=" " ind2=" ">
          <marc:subfield code="n">
            <xsl:apply-templates select="working_paper_peer_reviewed"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- URL -->
    <xsl:choose>
      <xsl:when test="working_paper_url">
        <marc:datafield tag="856" ind1="4" ind2="0">
          <marc:subfield code="u">
            <xsl:apply-templates select="working_paper_url"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>
  </xsl:template>


<!--##########################-->
<!-- Journal Article Template -->
<!--##########################-->
  <xsl:template name="journal_article">

<!-- ISSN -->
    <xsl:choose>
      <xsl:when test="journal_issn">
        <marc:datafield tag="022" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="journal_article_issn"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- DOI -->
    <xsl:choose>
      <xsl:when test="journal_doi">
        <marc:datafield tag="024" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="journal_doi"/>
          </marc:subfield>
          <marc:subfield code="2">doi</marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Journal Title / Refereed / Volume / Issue / Pages -->
    <xsl:choose>
      <xsl:when test="journal_title">
        <marc:datafield tag="787" ind1=" " ind2=" ">
          <marc:subfield code="t">
            <xsl:apply-templates select="journal_title"/>
          </marc:subfield>
          <marc:subfield code="n">
            <xsl:apply-templates select="journal_peer_reviewed"/>
          </marc:subfield>
          <xsl:choose>
            <xsl:when test="journal_volume">
              <marc:subfield code="g">Vol:<xsl:value-of select="journal_volume"/>
                       <xsl:choose><xsl:when test="journal_issue">; Issue:<xsl:value-of select="journal_issue"/></xsl:when></xsl:choose>
                       <xsl:choose><xsl:when test="journal_page_from">; pp.<xsl:value-of select="journal_page_from"/></xsl:when></xsl:choose>
                       <xsl:choose><xsl:when test="journal_page_to">-<xsl:value-of select="journal_page_to"/></xsl:when></xsl:choose>
                       </marc:subfield>
            </xsl:when>
          </xsl:choose>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Journal Publisher, Place of Publication, Date -->
    <xsl:choose>
      <xsl:when test="year">
        <marc:datafield tag="260" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="journal_place_publication"/>
          </marc:subfield>
          <marc:subfield code="b">
            <xsl:apply-templates select="journal_publisher"/>
          </marc:subfield>
          <marc:subfield code="c">
            <xsl:apply-templates select="year"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Total Pages -->
    <xsl:variable name="first" select="journal_page_to"/>
    <xsl:variable name="second" select="journal_page_from"/>
    <marc:datafield tag="300" ind1=" " ind2=" ">
      <marc:subfield code="a">
        <xsl:value-of select="number($first) - number($second) + number('1')"/>
      </marc:subfield>
    </marc:datafield>
  </xsl:template>


<!--##########################-->
<!-- Thesis Template -->
<!--##########################-->
  <xsl:template name="thesis">

<!-- Supervisors -->
    <xsl:choose>
      <xsl:when test="thesis_supervisor_last_name">
        <xsl:choose>
          <xsl:when test="thesis_supervisor_first_name">
            <xsl:choose>
              <xsl:when test="thesis_supervisor_affiliation">
                <marc:datafield tag="720" ind1=" " ind2=" ">
                  <marc:subfield code="a"><xsl:apply-templates select="thesis_supervisor_last_name"/>, <xsl:apply-templates select="thesis_supervisor_first_name"/>, <xsl:apply-templates select="thesis_supervisor_affiliation"/></marc:subfield>
                </marc:datafield>
              </xsl:when>
              <xsl:otherwise>
                <marc:datafield tag="720" ind1=" " ind2=" ">
                  <marc:subfield code="a"><xsl:apply-templates select="thesis_supervisor_last_name"/>, <xsl:apply-templates select="thesis_supervisor_first_name"/></marc:subfield>
                </marc:datafield>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <xsl:choose>
              <xsl:when test="thesis_supervisor_affiliation">
                <marc:datafield tag="720" ind1=" " ind2=" ">
                  <marc:subfield code="a"><xsl:apply-templates select="thesis_supervisor_last_name"/>, <xsl:apply-templates select="thesis_supervisor_affiliation"/></marc:subfield>
                </marc:datafield>
              </xsl:when>
              <xsl:otherwise>
                <marc:datafield tag="720" ind1=" " ind2=" ">
                  <marc:subfield code="a">
                    <xsl:apply-templates select="thesis_supervisor_last_name"/>
                  </marc:subfield>
                </marc:datafield>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
    </xsl:choose>

<!-- Other Supervisors -->
    <xsl:apply-templates select="*[starts-with(local-name(),'thesis_supervisor_last_name_')]"/>

<!-- Thesis Publisher, Place of Publication, Date -->
    <marc:datafield tag="260" ind1=" " ind2=" ">
      <xsl:choose>
        <xsl:when test="thesis_place_publication">
          <marc:subfield code="a">
            <xsl:apply-templates select="thesis_place_publication"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="thesis_publisher">
          <marc:subfield code="b">
            <xsl:apply-templates select="thesis_publisher"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="year">
          <marc:subfield code="c">
            <xsl:apply-templates select="year"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
    </marc:datafield>

<!-- Thesis Degree Program -->
    <xsl:choose>
      <xsl:when test="thesis_degree">
        <marc:datafield tag="502" ind1="3" ind2=" ">
          <marc:subfield code="u">
            <xsl:apply-templates select="thesis_degree"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>
  </xsl:template>




<!--##########################-->
<!-- Conference Paper Template -->
<!--##########################-->
  <xsl:template name="conference_paper">

<!-- Conference Location / Dates / Proceedings Title / Name / Refereed -->
    <marc:datafield tag="711" ind1="0" ind2=" ">
      <xsl:choose>
        <xsl:when test="conference_title">
          <marc:subfield code="t">
            <xsl:apply-templates select="conference_title"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="conference_location">
          <marc:subfield code="c">
            <xsl:apply-templates select="conference_location"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="year">
          <xsl:choose>
            <xsl:when test="conference_month">
              <marc:subfield code="d">
                <xsl:apply-templates select="conference_month"/> <xsl:apply-templates select="year"/>
              </marc:subfield>
            </xsl:when>
            <xsl:otherwise>
              <marc:subfield code="d">
                <xsl:apply-templates select="year"/>
              </marc:subfield>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
      </xsl:choose>
    </marc:datafield>

<!-- Conference Name -->
    <marc:datafield tag="787" ind1=" " ind2="0">
      <xsl:choose>
        <xsl:when test="conference_name">
          <marc:subfield code="a">
            <xsl:apply-templates select="conference_name"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>

<!-- Conference Peer Reviewed -->
      <xsl:choose>
        <xsl:when test="conference_peer_reviewed">
          <marc:subfield code="n">
            <xsl:apply-templates select="conference_peer_reviewed"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>

<!-- Conference Page -->
      <xsl:choose>
        <xsl:when test="conference_page_from">
          <marc:subfield code="g">pp.<xsl:apply-templates select="conference_page_from"/>
           <xsl:choose><xsl:when test="conference_page_to">-<xsl:apply-templates select="conference_page_to"/></xsl:when></xsl:choose>
           </marc:subfield>
        </xsl:when>
      </xsl:choose>
    </marc:datafield>
<!--
       <marc:subfield code="c">
               <xsl:apply-templates select="conference_location"/>
       </marc:subfield>
       <marc:subfield code="d">
               <xsl:apply-templates select="conference_date"/>
       </marc:subfield>
        <marc:subfield code="t">
               <xsl:apply-templates select="conference_title"/>
       </marc:subfield>
-->

<!-- ISBN -->
    <xsl:choose>
      <xsl:when test="conference_isbn">
        <marc:datafield tag="020" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="conference_isbn"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- ISSN -->
    <xsl:choose>
      <xsl:when test="conference_issn">
        <marc:datafield tag="022" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="conference_issn"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Conference Publisher, Place of Publication, Date -->
    <marc:datafield tag="260" ind1=" " ind2=" ">
      <xsl:choose>
        <xsl:when test="conference_place_publication">
          <marc:subfield code="a">
            <xsl:apply-templates select="conference_place_publication"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="conference_publisher">
          <marc:subfield code="b">
            <xsl:apply-templates select="conference_publisher"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="conference_proceedings_year">
          <marc:subfield code="c">
            <xsl:apply-templates select="conference_proceedings_year"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
    </marc:datafield>

<!-- COnference URL -->
<!--
    <xsl:choose>
      <xsl:when test="conference_url">
       <marc:datafield tag="773" ind1=" " ind2=" ">
            <marc:subfield code="t">
               <xsl:apply-templates select="conference_url"/>
            </marc:subfield>
       </marc:datafield>
      </xsl:when>
    </xsl:choose>
-->
    <xsl:choose>
      <xsl:when test="conference_url">
        <marc:datafield tag="856" ind1="4" ind2="0">
          <marc:subfield code="u">
            <xsl:apply-templates select="conference_url"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Conference Total Pages -->
    <xsl:variable name="first" select="conference_page_to"/>
    <xsl:variable name="second" select="conference_from"/>
    <marc:datafield tag="300" ind1=" " ind2=" ">
      <marc:subfield code="a">
        <xsl:value-of select="number($first) - number($second)"/>
      </marc:subfield>
    </marc:datafield>
  </xsl:template>

<!--##########################-->
<!-- Conference Item Template -->
<!--##########################-->
  <xsl:template name="conference_item">

<!-- Conference Location / Dates / Proceedings Title / Name / Refereed -->
    <marc:datafield tag="711" ind1="0" ind2=" ">
      <xsl:choose>
        <xsl:when test="conference_item_title">
          <marc:subfield code="t">
            <xsl:apply-templates select="conference_item_title"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="conference_item_location">
          <marc:subfield code="c">
            <xsl:apply-templates select="conference_item_location"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="year">
          <xsl:choose>
            <xsl:when test="conference_item_date">
              <marc:subfield code="d">
                <xsl:apply-templates select="conference_item_date"/>
                <xsl:apply-templates select="year"/>
              </marc:subfield>
            </xsl:when>
            <xsl:otherwise>
              <marc:subfield code="d">
                <xsl:apply-templates select="year"/>
              </marc:subfield>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
      </xsl:choose>
    </marc:datafield>

<!-- Conference Name -->
    <marc:datafield tag="787" ind1=" " ind2="0">
      <xsl:choose>
        <xsl:when test="conference_item_name">
          <marc:subfield code="a">
            <xsl:apply-templates select="conference_item_name"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>

<!-- Conference Peer Reviewed -->
      <xsl:choose>
        <xsl:when test="conference_item_peer_reviewed">
          <marc:subfield code="n">
            <xsl:apply-templates select="conference_item_peer_reviewed"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>

<!-- Conference Page -->
      <xsl:choose>
        <xsl:when test="conference_item_page_from">
          <marc:subfield code="g">pp.<xsl:apply-templates select="conference_item_page_from"/>
           <xsl:choose><xsl:when test="conference_item_page_to">-<xsl:apply-templates select="conference_item_page_to"/></xsl:when></xsl:choose>
           </marc:subfield>
        </xsl:when>
      </xsl:choose>
    </marc:datafield>
<!--
       <marc:subfield code="c">
               <xsl:apply-templates select="conference_item_location"/>
       </marc:subfield>
       <marc:subfield code="d">
               <xsl:apply-templates select="conference_item_date"/>
       </marc:subfield>
        <marc:subfield code="t">
               <xsl:apply-templates select="conference_item_title"/>
       </marc:subfield>
-->

<!-- ISBN -->
    <xsl:choose>
      <xsl:when test="conference_item_isbn">
        <marc:datafield tag="020" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="conference_item_isbn"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- ISSN -->
    <xsl:choose>
      <xsl:when test="conference_item_issn">
        <marc:datafield tag="022" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="conference_item_issn"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Conference Publisher, Place of Publication, Date -->
    <marc:datafield tag="260" ind1=" " ind2=" ">
      <xsl:choose>
        <xsl:when test="conference_place_item_publication">
          <marc:subfield code="a">
            <xsl:apply-templates select="conference_item_place_publication"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="conference_item_publisher">
          <marc:subfield code="b">
            <xsl:apply-templates select="conference_item_publisher"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="conference_item_proceedings_year">
          <marc:subfield code="c">
            <xsl:apply-templates select="year"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
    </marc:datafield>

<!-- COnference URL -->
<!--
    <xsl:choose>
      <xsl:when test="conference_item_url">
       <marc:datafield tag="773" ind1=" " ind2=" ">
            <marc:subfield code="t">
               <xsl:apply-templates select="conference_item_url"/>
            </marc:subfield>
       </marc:datafield>
      </xsl:when>
    </xsl:choose>
-->
    <xsl:choose>
      <xsl:when test="conference_item_url">
        <marc:datafield tag="856" ind1="4" ind2="0">
          <marc:subfield code="u">
            <xsl:apply-templates select="conference_item_url"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Conference Total Pages -->
    <xsl:variable name="first" select="conference_item_page_to"/>
    <xsl:variable name="second" select="conference_item_from"/>
    <marc:datafield tag="300" ind1=" " ind2=" ">
      <marc:subfield code="a">
        <xsl:value-of select="number($first) - number($second)"/>
      </marc:subfield>
    </marc:datafield>
  </xsl:template>


<!--##########################-->
<!-- Book Chapter Template -->
<!--##########################-->
  <xsl:template name="book_chapter">

<!-- Editors -->
    <xsl:choose>
      <xsl:when test="editor_last_name">
        <xsl:choose>
          <xsl:when test="editor_first_name">
            <marc:datafield tag="700" ind1="1" ind2=" ">
              <marc:subfield code="a"><xsl:apply-templates select="editor_last_name"/>, <xsl:apply-templates select="editor_first_name"/></marc:subfield>
              <marc:subfield code="e">Editor</marc:subfield>
            </marc:datafield>
          </xsl:when>
          <xsl:otherwise>
            <marc:datafield tag="700" ind1="1" ind2=" ">
              <marc:subfield code="a">
                <xsl:apply-templates select="editor_last_name"/>
              </marc:subfield>
              <marc:subfield code="e">Editor</marc:subfield>
            </marc:datafield>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
    </xsl:choose>

<!-- Other Editors -->
    <xsl:apply-templates select="*[starts-with(local-name(),'editor_last_name_')]"/>

<!-- Book Chapter Publisher, Place of Publication, Date -->
    <xsl:choose>
      <xsl:when test="year">
        <marc:datafield tag="260" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="chapter_place_publication"/>
          </marc:subfield>
          <marc:subfield code="b">
            <xsl:apply-templates select="chapter_publisher"/>
          </marc:subfield>
          <marc:subfield code="c">
            <xsl:apply-templates select="year"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Book Chapter ISBN -->
    <xsl:choose>
      <xsl:when test="chapter_isbn">
        <marc:datafield tag="020" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="chapter_isbn"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Chapter Book Title / Details -->
    <marc:datafield tag="787" ind1=" " ind2="0">
<!--   
<marc:subfield code="g">Chapter <xsl:apply-templates select="chapter_number"/>, pp. <xsl:apply-templates select="chapter_page_from"/>-<xsl:apply-templates select="chapter_page_to"/></marc:subfield>
-->
      <xsl:choose>
        <xsl:when test="chapter_page_from">
          <marc:subfield code="g">pp.<xsl:apply-templates select="chapter_page_from"/>
            <xsl:choose><xsl:when test="chapter_page_to">-<xsl:apply-templates select="chapter_page_to"/></xsl:when></xsl:choose>
            </marc:subfield>
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="chapter_book_title">
          <marc:subfield code="t">
            <xsl:apply-templates select="chapter_book_title"/>
          </marc:subfield>
        </xsl:when>
      </xsl:choose>
    </marc:datafield>

<!-- Chapter Edition -->
    <xsl:choose>
      <xsl:when test="chapter_edition">
        <marc:datafield tag="250" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="chapter_edition"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Chapter Total Pages -->
    <xsl:variable name="first" select="chapter_page_to"/>
    <xsl:variable name="second" select="chapter_page_from"/>
    <marc:datafield tag="300" ind1=" " ind2=" ">
      <marc:subfield code="a">
        <xsl:value-of select="number($first) - number($second)"/>
      </marc:subfield>
    </marc:datafield>

<!-- Peer Reviewed -->
    <xsl:choose>
      <xsl:when test="chapter_peer_reviewed">
        <marc:datafield tag="787" ind1=" " ind2=" ">
          <marc:subfield code="n">
            <xsl:apply-templates select="chapter_peer_reviewed"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- URL -->
    <xsl:choose>
      <xsl:when test="chapter_url">
        <marc:datafield tag="856" ind1="4" ind2="0">
          <marc:subfield code="u">
            <xsl:apply-templates select="chapter_url"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>
  </xsl:template>


<!--##########################-->
<!-- Book Template -->
<!--##########################-->
  <xsl:template name="book">

<!-- Book Chapter Publisher, Place of Publication, Date -->
    <xsl:choose>
      <xsl:when test="year">
        <marc:datafield tag="260" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="book_place_publication"/>
          </marc:subfield>
          <marc:subfield code="b">
            <xsl:apply-templates select="book_publisher"/>
          </marc:subfield>
          <marc:subfield code="c">
            <xsl:apply-templates select="year"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Book ISBN -->
    <xsl:choose>
      <xsl:when test="book_isbn">
        <marc:datafield tag="020" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="book_isbn"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Book Edition -->
    <xsl:choose>
      <xsl:when test="book_edition">
        <marc:datafield tag="250" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="book_edition"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Peer Reviewed -->
    <xsl:choose>
      <xsl:when test="book_peer_reviewed">
        <marc:datafield tag="787" ind1=" " ind2=" ">
          <marc:subfield code="n">
            <xsl:apply-templates select="book_peer_reviewed"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- URL -->
    <xsl:choose>
      <xsl:when test="book_url">
        <marc:datafield tag="856" ind1="4" ind2="0">
          <marc:subfield code="u">
            <xsl:apply-templates select="book_url"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>
  </xsl:template>


<!--##########################-->
<!-- Report Template -->
<!--##########################-->
  <xsl:template name="report">

<!-- Report Publisher, Place of Publication, Date -->
    <xsl:choose>
      <xsl:when test="year">
        <marc:datafield tag="260" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="report_place_publication"/>
          </marc:subfield>
          <marc:subfield code="b">
            <xsl:apply-templates select="report_publisher"/>
          </marc:subfield>
          <marc:subfield code="c">
            <xsl:apply-templates select="year"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Report ISBN -->
    <xsl:choose>
      <xsl:when test="report_isbn">
        <marc:datafield tag="020" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="report_isbn"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Report Edition -->
    <xsl:choose>
      <xsl:when test="report_edition">
        <marc:datafield tag="250" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:apply-templates select="report_edition"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- Report Series Number -->
    <xsl:choose>
      <xsl:when test="report_series_no">
        <marc:datafield tag="830" ind1=" " ind2=" ">
          <marc:subfield code="v">
            <xsl:apply-templates select="report_series_no"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>

<!-- URL -->
    <xsl:choose>
      <xsl:when test="report_url">
        <marc:datafield tag="856" ind1="4" ind2="0">
          <marc:subfield code="u">
            <xsl:apply-templates select="report_url"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
    </xsl:choose>
  </xsl:template>


<!--##########################-->
<!-- Multiple Keywords -->
<!--##########################-->
  <xsl:template match="*[starts-with(local-name(),'keyword')]">
    <marc:datafield tag="653" ind1=" " ind2=" ">
      <marc:subfield code="a">
        <xsl:value-of select="."/>
      </marc:subfield>
    </marc:datafield>
  </xsl:template>


<!--##########################-->
<!-- Multiple Creators -->
<!--##########################-->
  <xsl:template match="*[starts-with(local-name(),'creator_last_name_')]">
    <xsl:variable name="num" select="substring-after(name(),'creator_last_name_')"/>
    <xsl:variable name="first_name" select="concat('creator_first_name_',$num)"/>
    <marc:datafield tag="700" ind1="1" ind2=" ">
      <marc:subfield code="a"><xsl:value-of select="."/>, <xsl:value-of select="//*[local-name()=$first_name]"/></marc:subfield>
    </marc:datafield>
  </xsl:template>


<!--##########################-->
<!-- Multiple Supervisors -->
<!--##########################-->
  <xsl:template match="*[starts-with(local-name(),'thesis_supervisor_last_name_')]">
    <xsl:variable name="num" select="substring-after(name(),'thesis_supervisor_last_name_')"/>
    <xsl:variable name="first_name" select="concat('thesis_supervisor_first_name_',$num)"/>
    <xsl:variable name="affiliation" select="concat('thesis_supervisor_affiliation_',$num)"/>
    <xsl:choose>
      <xsl:when test="//*[local-name()=$first_name]">
        <xsl:choose>
          <xsl:when test="//*[local-name()=$affiliation]">
            <marc:datafield tag="720" ind1=" " ind2=" ">
              <marc:subfield code="a"><xsl:value-of select="."/>, <xsl:value-of select="//*[local-name()=$first_name]"/>, <xsl:value-of select="//*[local-name()=$affiliation]"/></marc:subfield>
            </marc:datafield>
          </xsl:when>
          <xsl:otherwise>
            <marc:datafield tag="720" ind1=" " ind2=" ">
              <marc:subfield code="a"><xsl:value-of select="."/>, <xsl:value-of select="//*[local-name()=$first_name]"/></marc:subfield>
            </marc:datafield>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="//*[local-name()=$affiliation]">
            <marc:datafield tag="720" ind1=" " ind2=" ">
              <marc:subfield code="a"><xsl:value-of select="."/>, <xsl:value-of select="//*[local-name()=$affiliation]"/></marc:subfield>
            </marc:datafield>
          </xsl:when>
          <xsl:otherwise>
            <marc:datafield tag="720" ind1=" " ind2=" ">
              <marc:subfield code="a">
                <xsl:value-of select="."/>
              </marc:subfield>
            </marc:datafield>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


<!--##########################-->
<!-- Multiple Editors -->
<!--##########################-->
  <xsl:template match="*[starts-with(local-name(),'editor_last_name_')]">
    <xsl:variable name="num" select="substring-after(name(),'editor_last_name_')"/>
    <xsl:variable name="first_name" select="concat('editor_first_name_',$num)"/>
    <xsl:choose>
      <xsl:when test="//*[local-name()=$first_name]">
        <marc:datafield tag="700" ind1="1" ind2=" ">
          <marc:subfield code="a"><xsl:value-of select="."/>, <xsl:value-of select="//*[local-name()=$first_name]"/></marc:subfield>
          <marc:subfield code="e">Editor</marc:subfield>
        </marc:datafield>
      </xsl:when>
      <xsl:otherwise>
        <marc:datafield tag="700" ind1="1" ind2=" ">
          <marc:subfield code="a">
            <xsl:value-of select="."/>
          </marc:subfield>
          <marc:subfield code="e">Editor</marc:subfield>
        </marc:datafield>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


<!--##########################-->
<!-- Split Creators function  -->
<!--##########################-->
  <xsl:template name="splitStringNewline">
    <xsl:param name="stringLine"/>
    <xsl:choose>
      <xsl:when test="contains($stringLine,'&#13;')">
        <xsl:variable name="beforeCR" select="substring-before($stringLine,'&#13;')"/>
        <xsl:call-template name="splitStringCreatorOri">
          <xsl:with-param name="stringCreator" select="$beforeCR"/>
        </xsl:call-template>
        <xsl:variable name="afterCR" select="substring-after($stringLine,'&#13;')"/>
        <xsl:call-template name="splitStringNewlineNext">
          <xsl:with-param name="stringLine" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($stringLine,'&#10;')">
        <xsl:variable name="beforeCR" select="substring-before($stringLine,'&#10;')"/>
        <xsl:call-template name="splitStringCreatorOri">
          <xsl:with-param name="stringCreator" select="$beforeCR"/>
        </xsl:call-template>
        <xsl:variable name="afterCR" select="substring-after($stringLine,'&#10;')"/>
        <xsl:call-template name="splitStringNewlineNext">
          <xsl:with-param name="stringLine" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($stringLine,'&#xa;')">
        <xsl:variable name="beforeCR" select="substring-before($stringLine,'&#xa;')"/>
        <xsl:call-template name="splitStringCreatorOri">
          <xsl:with-param name="stringCreator" select="$beforeCR"/>
        </xsl:call-template>
        <xsl:variable name="afterCR" select="substring-after($stringLine,'&#xa;')"/>
        <xsl:call-template name="splitStringNewlineNext">
          <xsl:with-param name="stringLine" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="splitStringCreatorOri">
          <xsl:with-param name="stringCreator" select="$stringLine"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="splitStringNewlineNext">
    <xsl:param name="stringLine"/>
    <xsl:choose>
      <xsl:when test="contains($stringLine,'&#13;')">
        <xsl:variable name="beforeCR" select="substring-before($stringLine,'&#13;')"/>
        <xsl:call-template name="splitStringCreator">
          <xsl:with-param name="stringCreator" select="$beforeCR"/>
        </xsl:call-template>
        <xsl:variable name="afterCR" select="substring-after($stringLine,'&#13;')"/>
        <xsl:call-template name="splitStringNewlineNext">
          <xsl:with-param name="stringLine" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($stringLine,'&#10;')">
        <xsl:variable name="beforeCR" select="substring-before($stringLine,'&#10;')"/>
        <xsl:call-template name="splitStringCreator">
          <xsl:with-param name="stringCreator" select="$beforeCR"/>
        </xsl:call-template>
        <xsl:variable name="afterCR" select="substring-after($stringLine,'&#10;')"/>
        <xsl:call-template name="splitStringNewlineNext">
          <xsl:with-param name="stringLine" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($stringLine,'&#xa;')">
        <xsl:variable name="beforeCR" select="substring-before($stringLine,'&#xa;')"/>
        <xsl:call-template name="splitStringCreator">
          <xsl:with-param name="stringCreator" select="$beforeCR"/>
        </xsl:call-template>
        <xsl:variable name="afterCR" select="substring-after($stringLine,'&#xa;')"/>
        <xsl:call-template name="splitStringNewlineNext">
          <xsl:with-param name="stringLine" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="splitStringCreator">
          <xsl:with-param name="stringCreator" select="$stringLine"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="splitStringCreatorOri">
    <xsl:param name="stringCreator"/>
    <xsl:choose>
      <xsl:when test="contains($stringCreator,';')">
        <xsl:variable name="beforeCR" select="substring-before($stringCreator,';')"/>
        <marc:datafield tag="100" ind1=" " ind2=" ">
          <marc:subfield code="a">
            <xsl:value-of select="$beforeCR"/>
          </marc:subfield>
          <xsl:variable name="afterCR" select="substring-after($stringCreator,';')"/>
          <marc:subfield code="u">
            <xsl:value-of select="$afterCR"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="$stringCreator!=''">
            <marc:datafield tag="100" ind1=" " ind2=" ">
              <marc:subfield code="a">
                <xsl:value-of select="$stringCreator"/>
              </marc:subfield>
            </marc:datafield>
          </xsl:when>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="splitStringCreator">
    <xsl:param name="stringCreator"/>
    <xsl:choose>
      <xsl:when test="contains($stringCreator,';')">
        <xsl:variable name="beforeCR" select="substring-before($stringCreator,';')"/>
        <xsl:variable name="afterCR" select="substring-after($stringCreator,';')"/>
        <marc:datafield tag="100" ind1="1" ind2=" ">
          <marc:subfield code="a">
            <xsl:value-of select="$beforeCR"/>
          </marc:subfield>
          <xsl:choose>
            <xsl:when test="$afterCR!=''">
              <marc:subfield code="u">
                <xsl:value-of select="$afterCR"/>
              </marc:subfield>
            </xsl:when>
          </xsl:choose>
        </marc:datafield>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="$stringCreator!=''">
            <marc:datafield tag="100" ind1=" " ind2=" ">
              <marc:subfield code="a">
                <xsl:value-of select="$stringCreator"/>
              </marc:subfield>
            </marc:datafield>
          </xsl:when>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


<!--##########################-->
<!-- Multiple Subjects -->
<!--##########################-->
  <xsl:template name="splitString">
    <xsl:param name="string1"/>
    <xsl:choose>
      <xsl:when test="contains($string1,'&#13;')">
        <xsl:variable name="beforeCR" select="substring-before($string1,'&#13;')"/>
        <xsl:choose>
	   <xsl:when test="$beforeCR!=''">
             <marc:datafield tag="653" ind1=" " ind2=" ">
          	<marc:subfield code="a">
            	   <xsl:value-of select="$beforeCR"/>
          	</marc:subfield>
             </marc:datafield>
	   </xsl:when>
	</xsl:choose>
        <xsl:variable name="afterCR" select="substring-after($string1,'&#13;')"/>
        <xsl:call-template name="splitString">
          <xsl:with-param name="string1" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($string1,'&#10;')">
        <xsl:variable name="beforeCR" select="substring-before($string1,'&#10;')"/>
        <xsl:choose>
	   <xsl:when test="$beforeCR!=''">
             <marc:datafield tag="653" ind1=" " ind2=" ">
          	<marc:subfield code="a">
            	   <xsl:value-of select="$beforeCR"/>
          	</marc:subfield>
             </marc:datafield>
	   </xsl:when>
	</xsl:choose>
        <xsl:variable name="afterCR" select="substring-after($string1,'&#10;')"/>
        <xsl:call-template name="splitString">
          <xsl:with-param name="string1" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($string1,'&#xa;')">
        <xsl:variable name="beforeCR" select="substring-before($string1,'&#xa;')"/>
        <xsl:choose>
	   <xsl:when test="$beforeCR!=''">
             <marc:datafield tag="653" ind1=" " ind2=" ">
          	<marc:subfield code="a">
            	   <xsl:value-of select="$beforeCR"/>
          	</marc:subfield>
             </marc:datafield>
	   </xsl:when>
	</xsl:choose>
        <xsl:variable name="afterCR" select="substring-after($string1,'&#xa;')"/>
        <xsl:call-template name="splitString">
          <xsl:with-param name="string1" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="$string1!=''">
            <marc:datafield tag="653" ind1=" " ind2=" ">
              <marc:subfield code="a">
                <xsl:value-of select="$string1"/>
              </marc:subfield>
            </marc:datafield>
          </xsl:when>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


<!--##########################-->
<!-- Multiple Additional Info -->
<!--##########################-->
  <xsl:template name="splitStringInfo">
    <xsl:param name="stringLineInfo"/>
    <xsl:choose>
      <xsl:when test="contains($stringLineInfo,'&#13;')">
        <xsl:variable name="beforeCR" select="substring-before($stringLineInfo,'&#13;')"/>
        <xsl:variable name="afterCR" select="substring-after($stringLineInfo,'&#13;')"/>
        <xsl:value-of select="$beforeCR"/>
        <xsl:text>&#13;
</xsl:text>
        <xsl:call-template name="splitString">
          <xsl:with-param name="stringLineInfo" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($stringLineInfo,'&#10;')">
        <xsl:variable name="beforeCR" select="substring-before($stringLineInfo,'&#10;')"/>
        <xsl:variable name="afterCR" select="substring-after($stringLineInfo,'&#10;')"/>
        <xsl:value-of select="$beforeCR"/>
        <xsl:text>&#13;
</xsl:text>
        <xsl:call-template name="splitString">
          <xsl:with-param name="stringLineInfo" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="contains($stringLineInfo,'&#xa;')">
        <xsl:variable name="beforeCR" select="substring-before($stringLineInfo,'&#xa;')"/>
        <xsl:variable name="afterCR" select="substring-after($stringLineInfo,'&#xa;')"/>
        <xsl:value-of select="$beforeCR"/>
        <xsl:text>&#13;
</xsl:text>
        <xsl:call-template name="splitString">
          <xsl:with-param name="stringLineInfo" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="$stringLineInfo!=''">
            <xsl:value-of select="$stringLineInfo"/>
          </xsl:when>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


<!--##########################-->
<!-- For spliting faculty -->
<!--##########################-->
  <xsl:template name="splitFaculty">
    <xsl:param name="string1"/>
    <xsl:choose>
      <xsl:when test="contains($string1,'&#13;')">
        <xsl:variable name="beforeCR" select="substring-before($string1,'&#13;')"/>
        <marc:datafield tag="710" ind1=" " ind2=" ">
          <marc:subfield code="b">
            <xsl:value-of select="$beforeCR"/>
          </marc:subfield>
        </marc:datafield>
        <xsl:variable name="afterCR" select="substring-after($string1,'&#13;')"/>
        <xsl:call-template name="splitFaculty">
          <xsl:with-param name="string1" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <marc:datafield tag="710" ind1=" " ind2=" ">
          <marc:subfield code="b">
            <xsl:value-of select="$string1"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


<!--##########################-->
<!-- For spliting school -->
<!--##########################-->
  <xsl:template name="splitSchool">
    <xsl:param name="string1"/>
    <xsl:choose>
      <xsl:when test="contains($string1,'&#13;')">
        <xsl:variable name="beforeCR" select="substring-before($string1,'&#13;')"/>
        <marc:datafield tag="710" ind1=" " ind2=" ">
          <marc:subfield code="b">
            <xsl:value-of select="$beforeCR"/>
          </marc:subfield>
        </marc:datafield>
        <xsl:variable name="afterCR" select="substring-after($string1,'&#13;')"/>
        <xsl:call-template name="splitSchool">
          <xsl:with-param name="string1" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <marc:datafield tag="710" ind1=" " ind2=" ">
          <marc:subfield code="b">
            <xsl:value-of select="$string1"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


<!--##########################-->
<!-- For spliting research_unit -->
<!--##########################-->
  <xsl:template name="splitResearch">
    <xsl:param name="string1"/>
    <xsl:choose>
      <xsl:when test="contains($string1,'&#13;')">
        <xsl:variable name="beforeCR" select="substring-before($string1,'&#13;')"/>
        <marc:datafield tag="710" ind1=" " ind2=" ">
          <marc:subfield code="b">
            <xsl:value-of select="$beforeCR"/>
          </marc:subfield>
        </marc:datafield>
        <xsl:variable name="afterCR" select="substring-after($string1,'&#13;')"/>
        <xsl:call-template name="splitResearch">
          <xsl:with-param name="string1" select="$afterCR"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <marc:datafield tag="710" ind1=" " ind2=" ">
          <marc:subfield code="b">
            <xsl:value-of select="$string1"/>
          </marc:subfield>
        </marc:datafield>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>
